﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WinForm1
{
     public class DBHelper
    {
        public static readonly string conStr = "server=.;database=Blogs;uid=sa;pwd=123456";

        public static DataTable GetDataTable(string sql)
        {
            SqlConnection connection = new SqlConnection(conStr);

            SqlDataAdapter sqlData = new SqlDataAdapter(sql,connection);

            connection.Open();

            DataTable data = new DataTable();

            sqlData.Fill(data);

            return data;

        } 

        public static int AddOrSaveOrDelete(string sql)
        {
            SqlConnection connection = new SqlConnection(conStr);

            SqlCommand command = new SqlCommand(sql,connection);

            connection.Open();

            return command.ExecuteNonQuery();

        }

    }
}
